package com.gukun.springboot.tdengine.service.backuprecover.config;

import com.taosdata.jdbc.TSDBDriver;
import com.zaxxer.hikari.HikariDataSource;

import java.util.Properties;

/**
 * 对于不同类型的任务，先晨晨
 * @author zhang
 */
public class TDEngineConnPool {

    public static HikariDataSource getHikariDataSource(String jdbcUrl,int maxPoolSize){
        try{
            HikariDataSource dataSource = new HikariDataSource();
            dataSource.setDriverClassName("com.taosdata.jdbc.ws.WebSocketDriver");
            dataSource.setJdbcUrl(jdbcUrl);
            dataSource.setConnectionTimeout(10000);
            dataSource.setMaximumPoolSize(maxPoolSize);
            dataSource.setMinimumIdle(maxPoolSize);
            dataSource.setMaxLifetime(0);
            dataSource.setIdleTimeout(60000);
            dataSource.setDataSourceProperties(getProperties());
            dataSource.setConnectionTestQuery("SELECT SERVER_VERSION()");
            return dataSource;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 高性能写入相关配置
     * @return
     */
    private static Properties getProperties() {
        Properties properties = new Properties();
        properties.setProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD,"true");
        return properties;
    }
}
